home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / DOS / PRGMMING / PBC30.ZIP / FMTPHONE.BAS < prev    next >
Encoding:
BASIC Source File  |  1994-11-12  |  1.3 KB  |  37 lines

  1. '   +----------------------------------------------------------------------+
  2. '   |                                                                      |
  3. '   |        PBClone  Copyright (c) 1990-1994  Thomas G. Hanlin III        |
  4. '   |                                                                      |
  5. '   +----------------------------------------------------------------------+
  6.  
  7.  
  8.    DECLARE FUNCTION AscM% (St$, BYVAL Posn%)
  9.    DECLARE FUNCTION UpcaseI% (BYVAL Ch%)
  10.  
  11. FUNCTION FormatPhone$ (RawSt$)
  12.  
  13.    '--- toss any characters that aren't alphanumeric, 'n' also Q and Z
  14.    st$ = ""
  15.    FOR tmp% = 1 TO LEN(RawSt$)
  16.       ch% = UpcaseI%(AscM%(RawSt$, tmp%))
  17.       IF ch% >= 48 AND ch% <= 57 OR ch% >= 65 AND ch% < 90 AND ch% <> 81 THEN
  18.          st$ = st$ + CHR$(ch%)
  19.       END IF
  20.    NEXT
  21.  
  22.    '--- format the result based on the string length
  23.    IF LEN(st$) = 11 AND LEFT$(st$, 1) = "1" THEN
  24.       st$ = MID$(st$, 2)
  25.    END IF
  26.    SELECT CASE LEN(st$)
  27.       CASE 4
  28.          FormatPhone$ = st$
  29.       CASE 7
  30.          FormatPhone$ = LEFT$(st$, 3) + "-" + RIGHT$(st$, 4)
  31.       CASE 10
  32.          FormatPhone$ = "(" + LEFT$(st$, 3) + ") " + MID$(st$, 4, 3) + "-" + RIGHT$(st$, 4)
  33.       CASE ELSE
  34.          FormatPhone$ = ""
  35.    END SELECT
  36. END FUNCTION
  37.